package com.xgggh.redpack;

import android.content.Intent;
import android.databinding.DataBindingUtil;
import android.os.Bundle;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.widget.Toast;

import com.jakewharton.rxbinding2.view.RxView;
import com.xgggh.app.RxBaseActivity;
import com.xgggh.redpack.databinding.ActivitySponsorBinding;

import java.util.concurrent.TimeUnit;

import io.reactivex.Observable;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.functions.Consumer;

/**
 * @title  赞助红包
 */
public class SponsorActivity extends RxBaseActivity {
    ActivitySponsorBinding mBinding;
    private static final int sponsor_request_code=0x113;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        mBinding= DataBindingUtil.setContentView(this,R.layout.activity_sponsor);
        setSupportActionBar(mBinding.toolBarParent.toolbar);

        //个人中心
        RxView.clicks(mBinding.contentSponsor.navigationHeader)
                .throttleFirst(windowDuration, TimeUnit.SECONDS)
                .subscribeOn(AndroidSchedulers.mainThread())
                .compose(bindToLifecycle())
                .subscribe(new Consumer<Object>() {
                    @Override
                    public void accept(Object o) throws Exception {
                        profileActivity();
                    }
                });
            //分享红包
        Observable shareContainer= RxView.clicks(mBinding.contentSponsor.shareRedPackContainer);
        Observable shareIcon= RxView.clicks(mBinding.contentSponsor.shareRedPackIcon);
        Observable shareInfo= RxView.clicks(mBinding.contentSponsor.shareRedPackInfo);
        Observable share= RxView.clicks(mBinding.contentSponsor.shareRedPack);
            Observable.merge(shareContainer,shareIcon,shareInfo,share)
                .throttleFirst(windowDuration, TimeUnit.SECONDS)
                .subscribeOn(AndroidSchedulers.mainThread())
                .compose(bindToLifecycle())
                .subscribe(new Consumer<Object>() {
                    @Override
                    public void accept(Object o) throws Exception {
                        Toast.makeText(SponsorActivity.this, "分享红包", Toast.LENGTH_SHORT).show();
                        redPackActivity();
                    }
                });
        //指定人红包
        Observable toUserContainer= RxView.clicks(mBinding.contentSponsor.toUserRedPackContainer);
        Observable toUserIcon= RxView.clicks(mBinding.contentSponsor.toUserRedPackIcon);
        Observable toUserInfo= RxView.clicks(mBinding.contentSponsor.toUserRedPackInfo);
        Observable toUser= RxView.clicks(mBinding.contentSponsor.toUserRedPack);
            Observable.merge(toUserContainer,toUserIcon,toUserInfo,toUser)
                .throttleFirst(windowDuration, TimeUnit.SECONDS)
                .subscribeOn(AndroidSchedulers.mainThread())
                .compose(bindToLifecycle())
                .subscribe(new Consumer<Object>() {
                    @Override
                    public void accept(Object o) throws Exception {
                        Toast.makeText(SponsorActivity.this, "指定人红包", Toast.LENGTH_SHORT).show();
                        redPackActivity();
                    }
                });
        //二维码红包
        Observable qrCodeContainer= RxView.clicks(mBinding.contentSponsor.qrCodeRedPackContainer);
        Observable qrCodeIcon= RxView.clicks(mBinding.contentSponsor.qrCodeRedPackIcon);
        Observable qrCodeInfo= RxView.clicks(mBinding.contentSponsor.qrCodeRedPackInfo);
        Observable qrCode= RxView.clicks(mBinding.contentSponsor.qrCodeRedPack);
        Observable.merge(qrCodeContainer,qrCodeIcon,qrCodeInfo,qrCode)
                .throttleFirst(windowDuration, TimeUnit.SECONDS)
                .subscribeOn(AndroidSchedulers.mainThread())
                .compose(bindToLifecycle())
                .subscribe(new Consumer<Object>() {
                    @Override
                    public void accept(Object o) throws Exception {
                        Toast.makeText(SponsorActivity.this, "二维码红包", Toast.LENGTH_SHORT).show();
                        redPackActivity();
                    }
                });
    }



    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (resultCode==RESULT_OK && requestCode==sponsor_request_code){
            setResult(RESULT_OK,data);
            finish();
        }

    }




    private void redPackActivity(){
        Intent intent = new Intent(this,RedPackActivity.class);
        startActivityForResult(intent,sponsor_request_code);
    }

    private void profileActivity(){
        Intent intent = new Intent(this,ProfileActivity.class);
        startActivity(intent);
    }

    /**
     * @title 共享红包
     * @param view
     */
    public void ShareRedPack(View view) {
    }

    /**
     * @title 指定人红包
     * @param view
     */
    public void ToUserRedPack(View view) {
    }

    /**
     * @title  二维码红包(故事线/激励)
     * @param view
     */
    public void QRCodeRedPack(View view) {
    }


}
